import { ref } from 'vue'

const useDialog = <T extends (object | undefined)>() => {
  const dialogVisible = ref<boolean>(false)
  const dialogData = ref<T>()

  /**
   * 控制弹窗显示隐藏
   * @param visible 控制弹窗显示隐藏
   * @param record 传入弹窗内部的数据
   */
  const dialogControl = (visible: boolean, record?: T): void => {
    dialogData.value = record || {} as T
    dialogVisible.value = visible
  }

  return {
    dialogVisible,
    dialogData,
    dialogControl
  }
}

export {
  useDialog
}
